/*
 * Filename: /home/long/work/sample/c/2021-f0803/is_rnum.c
 * Path: /home/long/work/sample/c/2021-f0803
 * Created Date: Saturday, April 17th 2021, 2:16:12 pm
 * Author: long
 * 
 * 编写一个函数，函数功能为检查一个正整数是否为回文数。
 * Copyright (c) 2021 Your Company
 */
#include <stdio.h>

int is_rnum(int n)
{
    // 只对正整数有效
    int r=0; // 右边低位构造的数
    while(n>r) {
        int l = n % 10;
        n = n / 10;
        if (n==r) // aba型， 或a
            return 1;
        r = r * 10 + l;
        if (n == r) // abba 型
            return 1;
    }
    return 0;
}

void main()
{
    int rnum[] = {
        0,
        1,
        121,
        1221,
        12321,
        1233332
    };

    for (int i=0; i<sizeof(rnum)/sizeof(int); i++){
        printf("%d is rnum check: %d\n", rnum[i], is_rnum(rnum[i]));
    }
}